package com.study;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class Demo5 {
    public static void main(String[] args) {
        ClassLoader classLoader = Demo5.class.getClassLoader();
        InputStream resourceAsStream = classLoader.getResourceAsStream("config.properties");
        Properties properties = new Properties();
        try {
            properties.load(resourceAsStream);
            String className = properties.getProperty("className");  // com.study.Employee
            String methodName = properties.getProperty("methodName");  // work
            Class configClass = Class.forName(className);
            Constructor<?> configConstructor = configClass.getConstructor();
            Object object = configConstructor.newInstance();
            Method configMethod = configClass.getMethod(methodName);
            configMethod.invoke(object);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }finally {
            try {
                resourceAsStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
